package org.ruanjj.minsubarraylen;

class Solution {
    public int minSubArrayLen(int target, int[] nums) {
        int n = nums.length;
        int ans = n;

        if(n == 1){
            return nums[0] < target? 0:1;
        }

        int i = 0;
        int subSum = nums[i];
        int j = 1;

        while(i < n && j < n){
           if(subSum >= target){
               ans = Math.min(ans,j-i+1);

           }
        }


        return ans == n ? 0:ans;
    }
}
